<template>
  <div></div>
</template>

<script setup>
import { ethers } from 'ethers';

async function connectWallet() {
  if (typeof window.ethereum !== 'undefined') {
    const provider = new ethers.BrowserProvider(window.ethereum);
    await provider.send('eth_requestAccounts', []);
    const signer = await provider.getSigner();
    return signer;
  } else {
    console.error('MetaMask 未安装');
  }
}

async function sendTransaction() {
  const signer = await connectWallet();

  if (!signer) return;

  const tx = {
    to: '0xe5cAA9dC6DE9049757a22318753Db4cABC1c7b89',
    value: ethers.parseEther('0.0001') // 0.1 ETH
  };

  try {
    const transactionResponse = await signer.sendTransaction(tx);
    console.log('Transaction Response:', transactionResponse);

    const receipt = await transactionResponse.wait();
    console.log('Transaction confirmed in block number:', receipt.blockNumber);
  } catch (error) {
    console.error('Transaction Failed:', error);
  }
}

sendTransaction();
</script>

<style lang="scss" scoped></style>
